package algotithm.acwing.test788;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author zhouyanxiang
 * @Date 2021-01-2021/1/5-22:34
 */
public class Main {

//    static int N = 100010;
//    static int[] arr = new int[N];

    public static void main(String[] args) throws IOException{
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(reader.readLine());
        String[] strings = reader.readLine().split(" ");
        int[]arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = Integer.parseInt(strings[i]);
        }
        System.out.println(merge(arr,0,n-1));
        reader.close();
    }

    public static long merge(int[] nums,int l,int r)  {
        if (l >= r) {
            return 0;
        }
        int mid = l + r >> 1;
        long res = 0;
        res += merge(nums,l,mid) + merge(nums,mid+1,r);

        int[] tmp = new int[r - l + 1];
        int i = l, j = mid + 1, k = 0;
        while (i <= mid && j <= r) {
            if (nums[i] <= nums[j]) {
                tmp[k++] = nums[i++];
            } else {
                tmp[k++] = nums[j++];
                // 情况三
                res += mid - i + 1;
            }
        }

        // 扫尾
        while (i <= mid) {
            tmp[k++] = nums[i++];
        }
        while (j <= r) {
            tmp[k++] = nums[j++];
        }

        // tmp -> arr
        for (i = l, j = 0; i <= r; i++, j++) {
            nums[i] = tmp[j];
        }
        return res;
    }

}
